package io.gitee.zhangbinhub.admin.oauth.bus.publish

import io.gitee.zhangbinhub.admin.common.event.ReloadDataBusEvent
import io.gitee.zhangbinhub.admin.oauth.constant.BusEventMessage
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.cloud.bus.BusProperties
import org.springframework.context.ApplicationContext
import org.springframework.stereotype.Component

/**
 * @author zhang by 19/03/2019
 * @since JDK 11
 */
@Component
class RefreshEventPublish @Autowired
constructor(private val applicationContext: ApplicationContext, private val busProperties: BusProperties) {

    fun doNotifyUpdateApp() {
        val source = this
        applicationContext.publishEvent(
            ReloadDataBusEvent(
                busProperties.id,
                null,
                BusEventMessage.refreshApplication,
                source
            )
        )
    }

    fun doNotifyUpdateRuntime() {
        applicationContext.publishEvent(
            ReloadDataBusEvent(
                busProperties.id,
                null,
                BusEventMessage.refreshRuntime,
                this
            )
        )
    }

}
